home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14178 < prev    next >
Encoding:
Text File  |  1996-08-05  |  5.7 KB  |  152 lines

  1. Path: hoho.quake.net!usenet
  2. From: billf@jovial.com (Bill Foote)
  3. Newsgroups: comp.object,comp.lang.eiffel,comp.lang.c++,comp.lang.beta,comp.lang.java,comp.lang.sather
  4. Subject: Re: What Should An Exception Handling Do? -- Clarification of rules
  5. Date: 29 Mar 1996 07:55:27 GMT
  6. Organization: Jovial
  7. Message-ID: <4jg51f$n99@hoho.quake.net>
  8. References: <4j954n$mrq@kai.com> <1996Mar27.211117.5569@schbbs.mot.com> <4jefbd$k33@kai.com>
  9. NNTP-Posting-Host: l89.ip.quake.net
  10.  
  11. In article <4jefbd$k33@kai.com>, Arch Robison <robison@kai.com> wrote:
  12. >In article <1996Mar27.211117.5569@schbbs.mot.com> shang@corp.mot.com writes:
  13. >>If resumption semantics were inferior, why should we bother to get
  14. >>its "benefits" by simulating its semantics as below:
  15. >
  16. >I should have qualified my statement "inferior" to "inferior in most cases".
  17.  
  18. I'm still puzzled how providing *additional* functionality can make
  19. resumable exception semantics "inferior" (except for implementation
  20. considerations), but that's a nit.
  21.  
  22. >     bool retry;
  23. >     do {
  24. >     retry = false;
  25. >     try {
  26. >         result = do_something();
  27. >     }
  28. >     catch( condition1 ) {some_extraordinary_work1();  retry=true;}
  29. >     catch( condition2 ) {some_extraordinary_work2();  retry=true;}
  30. >     catch( condition3 ) {some_extraordinary_work3();  retry=true;}
  31. >         catch( condition4 ) {result=NULL;}
  32. >     } while( retry );
  33.  
  34. Well, here I go again, disagreeing with Bjarne, but:
  35.  
  36. This example misses the point of resumable exceptions.  If you can sensibly
  37. catch the exception at the point from which you want to resume, yes, of course,
  38. you don't need resumable execeptions.  Resumable exceptions only buy you
  39. something if the point where you can deal with the exception is one or more
  40. stack frames _above_ the point where the error occurs.  Here is an example 
  41. of something that you can't simulate with termination semantics:
  42.  
  43.     main()
  44.  
  45.     {
  46.     try {
  47.         call_something();
  48.     }
  49.     catch ( OutOfMemoryException& ex)  {
  50.         do_something_to_free_up_some_memory();
  51.         if (a_decent_amount_of_memory_was_freed())
  52.         retry;
  53.     }
  54.     }
  55.  
  56.     void call_something()
  57.  
  58.     {
  59.     <...>
  60.     call_something_else();
  61.     }
  62.  
  63.     void call_something_else()
  64.  
  65.     {
  66.     <...>
  67.     try {
  68.         auto_ptr<char> = malloc(A_REALLY_BIG_NUMBER);
  69.     }
  70.     }
  71.  
  72. The idea here is that the only place with enough context to know how
  73. to free up some memory (perhaps by flushing some caches or something)
  74. is main().  call_something_else() exists at too low a level to know
  75. how to do that.  If memory is low, the malloc() fails, and the exception
  76. handler in main() catches it, and then resume causes execution to go back
  77. to the point of failure.
  78.  
  79.  
  80. Now, Bjarne's claim is that, in practice, doing this sort of thing isn't
  81. useful.  He backs this up with reports of real-world experience, where
  82. large systems were built, and resumption semantics were found to not be
  83. useful, in practice.
  84.  
  85. This contention I cannot disagree with -- I don't have any experience
  86. with large systems using resumption semantics for its exceptions.
  87. It's pretty easy to concoct toy example where it seems compelling,
  88. but that doesn't really demonstrate that, in practical terms, it's
  89. useful.  (Of course, three or four case studies doesn't guarantee that
  90. it *isn't* useful, but it certainly supports the contention).
  91.  
  92. Does anyone out there know of examples from large systems where 
  93. resumption semantics proved valuable?
  94.  
  95. >The original attack on C++ unfairly implied that the C++ committee had given no
  96. >though to the issues.  
  97.  
  98. As the author of the "attack", I respectfully disagree.
  99.  
  100. I did not mean to imply that the C++ committee gave no thought to the issue.
  101.  
  102. I *did* imply that the fact that implementing resumable exceptions would
  103. be hard may have influenced the decision of the committe to not support 
  104. them.
  105.  
  106. (Incidentally, I did not think of my comment as an "attack".  Perhaps
  107. a "jibe", or "poking fun", but attack is much too strong a word.)
  108.  
  109. >As described in Stroustrup's D&E book, the C++ committee 
  110. >knowledgeably debated the resumption vs. termination models of exception 
  111. >handling and judged that the extra cost of the resumption model was not worth 
  112. >the cost in added complexity.
  113.  
  114. Exactly.  Given the definition of C++, it would be hard to implement
  115. resumable exceptions.  This may have played into the decision not to do
  116. it.  I think we're in violent agreement :-)
  117.  
  118. >Thus many apparently useful features are deliberately left out of C++ .
  119. >Users who want the features can simulate them without burdening others.
  120.  
  121. Aak!  Some things are very, very difficult to "simulate" without runtime
  122. support from the language.  Off the top of my head:
  123.  
  124.     *  Simulating MI in a SI language would be tough
  125.  
  126.     *  Block closures, and curried functions.
  127.  
  128.     *  Garbage Collection (with, of course, finalization and weak
  129.        references) is hard to "simulate".  (Not impossible, but
  130.        much, much harder than if it's put in the language).
  131.  
  132.     *  Resumable exceptions
  133.  
  134.     *  Meta-information.  (For example, try to write a framework that
  135.        automatically "pickles" an arbitrary C++ object.  You end up either
  136.        forcing the client to write his own pickling/unpickling code, or
  137.        relying on a preprocessor.  Both are painful.)
  138.  
  139.     *  RTTI a la C++.  dynamic_cast<T> is *awfully* hard to "simulate"
  140.        for all but trivial uses in a pre-RTTI C++ compiler.
  141.  
  142. >C++ is not intended to be the best language for all problems.
  143. >If another language is better for your problem, use it.
  144.  
  145. Of course.  But does that mean that all critical thought as to the merits
  146. of C++ should stop?  I certainly hope not!
  147.  
  148. --
  149. Bill Foote                       |  L'homme est nΘ pour vivre dans les
  150. billf@jovial.com                 |  convulsions de l'inquiΘtude ou dans la
  151. http://www.jovial.com/~billf/    |  lΘthargie de l'ennui       -- Voltaire
  152.